package com.infoland.afanmall.model.address.adapter;

import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.infoland.afanmall.R;
import com.infoland.afanmall.base.util.LogKit;
import com.infoland.afanmall.base.util.ToolsKit;
import com.infoland.afanmall.model.address.entity.AddressAllEntity;
import com.infoland.afanmall.model.address.linster.AddressClickLinster;

import java.util.List;

public class AddressAllAdapter extends BaseQuickAdapter<AddressAllEntity, BaseViewHolder> {
    public AddressAllAdapter(List<AddressAllEntity> data) {
        super(R.layout.address_item, data);

    }

    @Override
    protected void convert(BaseViewHolder helper, AddressAllEntity item) {
        /*** 编辑地址信息**/
        helper.getView(R.id.address_bianji).setOnClickListener(v -> {
            addressClickLinster.onclick(item.getId(),0);
        });
        /*** 执行地址选中事件**/
        helper.getView(R.id.select_check).setOnClickListener(v -> {
            addressClickLinster.onclick(item.getId(),1);
        });
        /*** 执行地址选中事件**/
        helper.getView(R.id.address_dati).setOnClickListener(v -> {
            addressClickLinster.onclick(item.getId(),1);
        });
        /*** 设置用户名**/
        helper.setText(R.id.address_name, "" + item.getReceiver_name());
        /*** 设置是否默认**/
        AppCompatTextView view = helper.getView(R.id.address_moren);
        AppCompatImageView img_yuan = helper.getView(R.id.address_img);
        AppCompatImageView address_dati = helper.getView(R.id.address_dati);
        if (item.getDefault_flag() == 1) {
            //            默认
            view.setVisibility(View.VISIBLE);
            img_yuan.setVisibility(View.VISIBLE);
            address_dati.setVisibility(View.GONE);
            view.setText("[默认]");
            ToolsKit.setImgView(R.mipmap.duihao, img_yuan);
        } else {
            //            非默认
            view.setVisibility(View.GONE);
            img_yuan.setVisibility(View.GONE);
            address_dati.setVisibility(View.VISIBLE);
            view.setText("");
        }

        if (item.getAddress_label() != null) {
            helper.setText(R.id.address_weizhi, item.getAddress_label());
        } else {
            helper.getView(R.id.address_weizhi).setVisibility(View.GONE);
        }
        helper.setText(R.id.address_phone, "" + item.getReceiver_tel());
        helper.setText(R.id.address_content, "" + item.getProvince_city_area() + item.getUser_address());



    }

    AddressClickLinster addressClickLinster;

    public void setAddressClickLinster(AddressClickLinster addressClickLinster) {
        this.addressClickLinster = addressClickLinster;
    }
}
